package com.nokia.ion.sdu.cdr_decoder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by vicwang on 2016/8/23.
 */
public class Cdr {
    public static final int TAG_chargingId = 5;
    public static final int TAG_accessPointNameNI = 7;
    public static final int TAG_nodeId = 18;
    public static final int TAG_servedIMSI = 3;
    public static final int TAG_servedMSISDN = 22;
    public static final int TAG_servedIMEISV = 29;
    public static final int TAG_rATType = 30;
    public static final int TAG_causeForRecClosing = 15;
    public static final int TAG_recordOpeningTime = 13;
    public static final int TAG_duration = 14;
    public static final int TAG_userLocationInformation = 32;
    public static final int TAG_pGWAddress = 4;
    public static final int TAG_servingNodeAddress = 6;
    public static final int TAG_recordSequenceNumber = 17;
    public static final int TAG_listOfServiceData = 34;

    public boolean last = false;

    public int cdrLength;
    public int recordType;
    public String nodeID = "Unknown";
    public String accessPointNameNI = "Unknown";

    public String pGWAddress = "Unknown";
    public String servingNodeAddress = "Unknown";

    public byte sgsnLoc = 0;

    public int chargingId;

    public Date recordOpeningTime;
    public int duration;

    public long servedIMSI;
    public long servedMSISDN;
    public long servedIMEISV;
    public String userLocationInformation;

    public int causeForRecClosing;
    public int recordSequenceNumber;

    public int rATType;
    public int serviceIdentifier;

    public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    public static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");

    public static final SimpleDateFormat localFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");

    private static final char spe = ',';

    @Override
    public String toString() {
        String res = String.format(" NodeId: %s\n chargingId: %d\n S_Addr: %s\n open_time: %s\n duration: %d\n cause: %d\n imsi: 0x%x\n sgsn location: %d\n",
                nodeID, chargingId, servingNodeAddress, localFormat.format(recordOpeningTime), duration, causeForRecClosing, servedIMSI, sgsnLoc);
        return res;
    }

    public static String generateHeader() {
        return "##date;time;node_id;msisdn;rat_type;duration;cause_for_close;rg0Uplink;rg0Downlink;rgxUplink;rgxDownlink##\n";
    }
}
